import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';

/// 有参数页面
class WithParamsPage extends StatelessWidget {
  final String title;
  final String? description;
  final int? count;

  const WithParamsPage({
    super.key,
    required this.title,
    this.description,
    this.count,
  });

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('有参数页面 - $title'),
        backgroundColor: Colors.green,
        foregroundColor: Colors.white,
      ),
      body: Padding(
        padding: const EdgeInsets.all(16.0),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Card(
              child: Padding(
                padding: const EdgeInsets.all(16.0),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Row(
                      children: [
                        const Icon(Icons.info, color: Colors.green),
                        const SizedBox(width: 8),
                        Text(
                          '页面信息',
                          style: Theme.of(context).textTheme.headlineSmall,
                        ),
                      ],
                    ),
                    const SizedBox(height: 16),
                    _buildInfoRow('标题', title),
                    if (description != null) _buildInfoRow('描述', description!),
                    if (count != null) _buildInfoRow('计数', count.toString()),
                  ],
                ),
              ),
            ),
            const SizedBox(height: 20),
            const Text(
              '这是一个带参数的页面示例。参数可以通过路由传递，也可以通过查询参数传递。',
              style: TextStyle(fontSize: 16),
            ),
            const SizedBox(height: 20),
            ElevatedButton(
              onPressed: () {
                context.go('/with-params/动态标题?description=动态描述&count=42');
              },
              child: const Text('跳转到另一个参数页面'),
            ),
          ],
        ),
      ),
    );
  }

  Widget _buildInfoRow(String label, String value) {
    return Padding(
      padding: const EdgeInsets.symmetric(vertical: 4.0),
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          SizedBox(
            width: 80,
            child: Text(
              '$label:',
              style: const TextStyle(
                fontWeight: FontWeight.bold,
                color: Colors.grey,
              ),
            ),
          ),
          Expanded(
            child: Text(
              value,
              style: const TextStyle(fontSize: 16),
            ),
          ),
        ],
      ),
    );
  }
}
